package com.ruoyi.web.controller.durian;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.durian.service.LlCardPackageService;
import com.ruoyi.durian.service.LlCouponService;
import com.ruoyi.durian.service.LlThaliRecordService;
import com.ruoyi.durian.service.LlThaliService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 优惠券控制器
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/coupon")
public class CouponController extends BaseController {
    @Resource
    private LlCouponService llCouponService;
    @Resource
    private LlCardPackageService llCardPackageService;
    @Resource
    private LlThaliService llThaliService;
    @Resource
    private LlThaliRecordService llThaliRecordService;

    /**
     * 优惠券详情
     *
     * @param id
     * @return
     */
    @GetMapping("/coupon/info/{id}")
    public AjaxResult couponInfo(@PathVariable Integer id) {
        return AjaxResult.success(llCouponService.selectByCouponId(id));
    }

    /**
     * 失效券列表
     *
     * @param
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo selectList() {
        startPage();
        return getDataTable(llCardPackageService.selectList());
    }

    /**
     * 套餐列表
     *
     * @return
     */
    @GetMapping("/thali/list")
    public TableDataInfo thaliList() {
        startPage();
        return getDataTable(llThaliService.thaliList());
    }

    /**
     * 套餐详情
     *
     * @return
     */
    @GetMapping("/thali/info/{id}")
    public AjaxResult thaliInfo(@PathVariable Integer id) {
        return llThaliService.thaliInfo(id);
    }

    /**
     * 套餐购买记录
     *
     * @return
     */
    @GetMapping("/thali/buy/list")
    public TableDataInfo thaliBuyList() {
        startPage();
        return getDataTable(llThaliRecordService.thaliBuyList());
    }

    /**
     * 购买套餐
     *
     * @return
     */
    @PostMapping("/thali/buy")
    public AjaxResult thaliBuy(@RequestParam("id") Integer id) {
        return llThaliRecordService.thaliBuy(id);
    }

    /**
     * 我的卡券列表
     *
     * @return
     */
    @GetMapping("/cardPackage/list")
    public TableDataInfo myCardList() {
        startPage();
        return getDataTable(llThaliService.myCardList());
    }

    /**
     * 查询我的卡券未失效的数量
     *
     * @return
     */
    @GetMapping("/couponCount")
    public Long couponCount() {
        return llCouponService.couponCount();
    }

    /**
     * 我的购买记录
     *
     * @return
     */
    @GetMapping("/myPayList")
    public TableDataInfo myPayList() {
        Integer userId = Integer.parseInt(SecurityUtils.getUserId().toString());
        return getDataTable(llThaliRecordService.myPayList(userId));
    }

}
